﻿using System;
using System.Data.SqlClient;

namespace Project.dalSql
{
public class dalTransaction : MarshalByRefObject
    {
        public SqlConnection conn = null;
        public SqlTransaction myTrans = null;

        public dalTransaction()
        {
            conn = new SqlConnection(dalSqlHelper.CONN_STRING_NON_DTC);
        }
        public void BeginTransaction()
        {
            if (conn != null)
            {
                conn.Open();
                myTrans = conn.BeginTransaction();
            }
        }

        public void BeginTransaction(string strTransactionName)
        {
            if (conn != null)
            {
                conn.Open();
                myTrans = conn.BeginTransaction(strTransactionName);
            }
        }

        public void Commit()
        {
            if (myTrans != null)
            {
                myTrans.Commit();
                conn.Close();
                myTrans = null;
            }
        }

        public void Rollback()
        {
            if (myTrans != null)
            {
                myTrans.Rollback();
                conn.Close();
                myTrans = null;
            }
        }

        public void Rollback(string strTransactionName)
        {
            if (myTrans != null)
            {
                myTrans.Rollback(strTransactionName);
                conn.Close();
                myTrans = null;
            }
        }

        public void Save(string strTransactionName)
        {
            if (myTrans != null)
            {
                myTrans.Save(strTransactionName);
            }
        }

        public void Close()
        {
            conn.Close();
        }

        public void Open()
        {
            conn.Open();
        }
    }
}
